package com.spdb.spdbfl.utils;

import com.spdb.spdbfl.database.DBInfo;
import com.spdb.spdbfl.database.DBOperate;

import java.util.List;
import java.util.Map;

public class GetBaseDataUtil {
    public GetBaseDataUtil() {
    }

    /**
     * 根据账户获取user_id
     * @param userAccount
     * @return
     */
    public static String getUserId(String userAccount) {
        String conn = DBInfo.getConn("baseDB");
        String sql = "select * from base.app_user where user_account ='" + userAccount + "';";

        List<Map<String, Object>> result = DBOperate.select(conn, sql);
        String user_id = (String) result.get(0).get("user_id");
        System.out.println(user_id);
        return user_id;
    }

    /**
     * 根据项目id获取关联的application_id
     * @param projectId
     * @return
     */
    public static String getApplicationByPro(String projectId){
        String conn = DBInfo.getConn("puYinDB");
        String sql = "SELECT * from  wf_project_approval where project_id = '" + projectId + "';";

        List<Map<String, Object>> result = DBOperate.select(conn, sql);
        if(result.size()>0){
            String application_id = (String)result.get(0).get("APPLICATION_ID");
            System.out.println("application_id:" + application_id);
            return application_id;
        }
        return null;
    }

    /**
     * 根据项目id获取project_approval_id
     * @param projectId
     * @return
     */
    public static String getProjectApprovalId(String projectId){
        String conn = DBInfo.getConn("puYinDB");
        String sql = "SELECT * from  wf_project_approval where project_id = '" + projectId + "';";

        List<Map<String, Object>> result = DBOperate.select(conn, sql);
        if(result.size()>0){
            String project_approval_id = (String)result.get(0).get("project_approval_id");
            System.out.println("project_approval_id:" + project_approval_id);
            return project_approval_id;
        }
        return null;
    }

    /**
     * 根据项目id获取applicationId
     * @param projectId
     * @return
     */
    public static String getApplicationId(String projectId){
        String conn = DBInfo.getConn("puYinDB");
        String sql = "SELECT * from  wf_application where PROJECT_ID = '" + projectId + "';";

        List<Map<String, Object>> result = DBOperate.select(conn, sql);
        if(result.size()>0){
            String applicationId = (String)result.get(0).get("ID");
            System.out.println("applicationId:" + applicationId);
            return applicationId;
        }
        return null;
    }

    /**
     * 获取租赁物名称
     * @param leaseItemId
     * @return
     */
    public static String getItemName(String leaseItemId){
        String conn = DBInfo.getConn("puYinDB");
        String sql = "SELECT * from  lease_item where LEASE_ITEM_ID = '" + leaseItemId + "';";

        List<Map<String, Object>> result = DBOperate.select(conn, sql);
        if(result.size()>0){
            String itemName = (String)result.get(0).get("ITEM_NAME");
            System.out.println("itemName:" + itemName);
            return itemName;
        }
        return null;
    }

    /**
     * 根据projectId获取ProjectCode
     * @param projectId
     * @return
     */
    public static String getProjectCode(String projectId){
        String conn = DBInfo.getConn("puYinDB");
        String sql = "SELECT * from project where PROJECT_ID = '" + projectId + "';";

        List<Map<String, Object>> result = DBOperate.select(conn, sql);
        if(result.size()>0){
            String projectCode = (String)result.get(0).get("PROJECT_CODE");
            System.out.println("projectCode:" + projectCode);
            return projectCode;
        }
        return null;
    }


    public static void main(String[] args) {
        getProjectCode("35012118c2c04c309e970f26598616c9");
    }
}
